package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TbInstitution;
import com.ruoyi.system.service.ITbInstitutionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 机构表Controller
 * 
 * @author tt
 * @date 2025-02-17
 */
@RestController
@RequestMapping("/system/institution")
public class TbInstitutionController extends BaseController
{
    @Autowired
    private ITbInstitutionService tbInstitutionService;

    /**
     * 查询机构表列表
     */
    @PreAuthorize("@ss.hasPermi('system:institution:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbInstitution tbInstitution)
    {
        startPage();
        List<TbInstitution> list = tbInstitutionService.selectTbInstitutionList(tbInstitution);
        return getDataTable(list);
    }

    /**
     * 导出机构表列表
     */
    @PreAuthorize("@ss.hasPermi('system:institution:export')")
    @Log(title = "机构表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbInstitution tbInstitution)
    {
        List<TbInstitution> list = tbInstitutionService.selectTbInstitutionList(tbInstitution);
        ExcelUtil<TbInstitution> util = new ExcelUtil<TbInstitution>(TbInstitution.class);
        util.exportExcel(response, list, "机构表数据");
    }

    /**
     * 获取机构表详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:institution:query')")
    @GetMapping(value = "/{institutionCode}")
    public AjaxResult getInfo(@PathVariable("institutionCode") String institutionCode)
    {
        return success(tbInstitutionService.selectTbInstitutionByInstitutionCode(institutionCode));
    }

    /**
     * 新增机构表
     */
    @PreAuthorize("@ss.hasPermi('system:institution:add')")
    @Log(title = "机构表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbInstitution tbInstitution)
    {
        return toAjax(tbInstitutionService.insertTbInstitution(tbInstitution));
    }

    /**
     * 修改机构表
     */
    @PreAuthorize("@ss.hasPermi('system:institution:edit')")
    @Log(title = "机构表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbInstitution tbInstitution)
    {
        return toAjax(tbInstitutionService.updateTbInstitution(tbInstitution));
    }

    /**
     * 删除机构表
     */
    @PreAuthorize("@ss.hasPermi('system:institution:remove')")
    @Log(title = "机构表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{institutionCodes}")
    public AjaxResult remove(@PathVariable String[] institutionCodes)
    {
        return toAjax(tbInstitutionService.deleteTbInstitutionByInstitutionCodes(institutionCodes));
    }
}
